//
//  LRProfileController.swift
//  LRWeibo
//
//  Created by 雷路荣 on 15/12/15.
//  Copyright © 2015年 leilurong. All rights reserved.
//

import UIKit

import SDWebImage
import SVProgressHUD
class LRProfileController: LRBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(label)
        view.addSubview(button)
        
        label.frame = CGRectMake(100, 100, 200, 100)
        button.frame = CGRectMake(100, 300, 100, 30)
        
        label.text = "缓存大小"
        
        readCacheSize()
        
    }
    func readCacheSize(){
        SDWebImageManager.sharedManager().imageCache.calculateSizeWithCompletionBlock { (a, b) -> Void in
            print(NSHomeDirectory())
            print("获取到缓存大小：a:\(a)----b:\(b)")
            self.label.text = "缓存大小:\(CGFloat(b)/1000/1000) M"
        }
    }
    //清除缓存
    func clear(){
    SDWebImageManager.sharedManager().imageCache.clearDiskOnCompletion { () -> Void in
        SVProgressHUD.showSuccessWithStatus("清除缓存成功")
            self.readCacheSize()
        }
    }
    private lazy var label: UILabel  = UILabel()
    
    private lazy var button: UIButton = {
        let button = UIButton()
        button.setTitle("清除缓存", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Highlighted)
        button.backgroundColor = UIColor.redColor()
        button.addTarget(self, action: "clear", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()

}
